import { observable, action } from 'mobx';
import sleep from '@/helpers/SleepHelper';

type AlertType = 'success' | 'error' | 'warning' | 'info';

export default class AlertStore {
    @observable public displayAlert = false;
    @observable public type: AlertType = 'info';
    @observable public text = '';

    @action
    public async show(text: string, type: AlertType = 'info', duration = 3000) {
        this.text = text;
        this.type = type;
        this.displayAlert = true;
        await sleep(duration);
        this.displayAlert = false;
    }
}
